<html>
<head>
<title>Sound Service Example</title>
<script type="text/javascript">
function Api()
{
	this.api=new Fireice();
}
Api.prototype= 
{
	stream:function ()
	{
		if(document.getElementById('streamRecord').value=="stop")
		{
			if(this.api.recording) {
				this.api.stop();
				document.getElementById('streamRecord').value="Record Stream";
				clearInterval(this.vu_update);
			}
			else {
				dump("Record is not running so can't Stop :)");
			}
		}
		else
		{		
			
			if(this.api.recording) {
				dump("Recorder is Already running");
			}
			else {
				var option={};
				option.server=document.getElementById('server').value;
				option.port = document.getElementById('port').value;
				option.password = document.getElementById('password').value;
				option.mount = document.getElementById('mount').value;
				var cmd = JSON.stringify(option);
				dump(this.api.recording);
				this.api.record(cmd);
				document.getElementById('streamRecord').value="stop";
			}
		}
		var _this = this;
		this.vu_update = setInterval(function() {_this.vu() }, 200);
		
	},
	local:function ()
	{
		if(document.getElementById('localRecord').value=="stop")
		{
			if(this.api.recording) {
				this.api.stop();
				document.getElementById('localRecord').value="Record Local";
				clearInterval(this.vu_update);
			}
			else {
				dump("Recorder is not Running So can't Stop :)");
			}
		}
		else
		{	
			if(this.api.recording) {
				dump("recorder is already running");
			}
			else {
				var d= new Date();
				var option={};
				option.server=d.getTime()+".ogg";
				alert(option.server);
				var cmd = JSON.stringify(option);
				dump(this.api.recording);
				this.api.record(cmd);
				document.getElementById('localRecord').value="stop";
			}
		}
		var _this = this;
		this.vu_update = setInterval(function() {_this.vu() }, 200);
	},	
	vu:function ()
	{
		if(this.api.recording) {
			a=this.api.vu();
			a= JSON.parse(a);
			document.getElementById('RMS').setAttribute('value',a.rms);
			document.getElementById('peak').setAttribute('value',a.peak);
			document.getElementById('decay').setAttribute('value',a.decay);
		}
		else {
			dump("Error:Recorder is not Running so can't show VU meter Data");
		}
	}	
}
var API=new Api();
</script>
</head>
<body>
<form name="form"><input type="button" value="Record Local"
	id="localRecord" onclick="API.local();" /><br />
<input type="text" name="server" id="server" /><br />
<input type="text" name="port" id="port" /><br />
<input type="password" name="password" id="password" /><br />
<input type="text" name="mount" id="mount" /><br />

<input type="button" value="Record Sound Live" id="streamRecord"
	onclick="API.stream();" /> <input type="button" value="VU Meter"
	id="vu" onclick="API.vu();" /> RMS:<input type="text" name="mount"
	id="RMS" /><br />
peak: <input type="text" id="peak" /><br />
decay: <input type="text" id="decay" /><br />
</form>
</body>
</html>
